package com.memory.monitor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.memory.monitor.annotation.AuthCheck;
import com.memory.monitor.common.BaseResponse;
import com.memory.monitor.common.DeleteRequest;
import com.memory.monitor.common.ResultUtils;
import com.memory.monitor.constant.UserConstant;

import com.memory.monitor.model.dto.station.StationAddRequest;
import com.memory.monitor.model.dto.station.StationQuerryRequest;
import com.memory.monitor.model.dto.station.StationUpdateRequest;
import com.memory.monitor.model.entity.Station;
import com.memory.monitor.service.StationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/station")
@Slf4j
public class StationController {
    @Resource
    private StationService stationService;

    /**
     * 分页获取信息列表（
     *
     * @param stationQuerryRequest
     * @param request
     * @return
     */
    @PostMapping("/list/page")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Page<Station>> listByPageStation(@RequestBody StationQuerryRequest stationQuerryRequest,
                                                         HttpServletRequest request) {
        long current = stationQuerryRequest.getCurrent();
        long size = stationQuerryRequest.getPageSize();
        // Page<User> userPage = userService.page(new Page<>(current, size),
        //         userService.getQueryWrapper(userQueryRequest));
        Page<Station> userPage = stationService.page(new Page<>(current, size));

        return ResultUtils.success(userPage);
    }

    /**
     * 增加信息  返回id
     *
     * @param stationAddRequest
     * @return
     */
    @PostMapping("/add")
    public BaseResponse<Long> addStation(@RequestBody StationAddRequest stationAddRequest) {
        Long id = stationService.addStation(stationAddRequest);
        return ResultUtils.success(id);
    }

    /**
     * 修改信息 返回boolean
     *
     * @param stationUpdateRequest
     * @return
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateStation(@RequestBody StationUpdateRequest stationUpdateRequest) {
        Boolean result = stationService.updateStation(stationUpdateRequest);
        return ResultUtils.success(result);
    }

    /**
     * 删除信息 返回boolean
     *
     * @param deleteRequest
     * @return
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteStation(@RequestBody DeleteRequest deleteRequest) {
        Boolean result = stationService.deleteStation(deleteRequest);
        return ResultUtils.success(result);
    }
}